// 水库chart
var reservoirChartOption = {
    chart: {
        zoomType: 'x'
    },
    exporting:{
    	enabled : false
    },
    xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: {
            day: '%m-%d',
            week: '%m-%d',
            month:'%y-%m-%d',
            year:'%y-%m-%d'
        }
    },
    yAxis: [{
        title: {
         text: '水位(mm)',
        },
        lineWidth : 1,

    },{
         title:{
        	 text :'流量(m³/s)'
          },
          lineWidth : 1,
          opposite:true
     }],
    credits:{
    	enabled:false
    },
    legend: {
        
        align: 'center',
        verticalAlign: 'bottom',
        borderWidth: 1
    },plotOptions:{
        series:{
            marker: {
                enabled: false
            }
        }
    },
    tooltip:{
    	shared: true,
    	crosshairs: true,
    	dateTimeLabelFormats: {
    		second:'%m-%d %H:%M',
    		minute:'%m-%d %H:%M',
    		hour:'%m-%d %H:%M',
            day: '%m-%d',
            week: '%m-%d',
            month:'%y-%m-%d',
            year:'%y-%m-%d'
        }
    }
}

function buildReservoirChart(windowVals,tabPanel){
	var id = tabPanel.attr('id');
	var bTm = windowVals.startTime;
	var eTm = windowVals.endTime;
	var dxn = windowVals.dxn;
	var stcd = tabPanel.data('stcd');
	var splitBTm = bTm.split('-');
	var startDate = new Date(splitBTm[0],splitBTm[1] - 1,splitBTm[2]);
	var chartParams = {};
	if(id == 'day'){
		chartParams.url = '../gis/ReservoirScreen.json?method=getSingleStatDayProcessByGisJs';
		chartParams.chartTitle = '逐日8时水位过程';	
		chartParams.seriesData = [
			{type: 'spline',name: '水位',color : 'green',dataVal : 'vals'},
			{type: 'spline',name: '限讯水位',color : '#FF0000',dataVal : 'totalVals'},
			{type: 'spline',name: '流量',color : '#00E3E3',dataVal : 'values5',yAxis:1,visible:false},
			{type: 'spline',name: '多年同期',color : '#FFFF37',dataVal : 'values1',visible:false},
			{type: 'spline',name: '典型年',color : '#FF00FF',dataVal : 'values6',visible:false}
		];
	}else if(id == 'hour'){
		chartParams.url = '../gis/ReservoirScreen.json?method=getSingleStatHourProcessByGisJs';
		chartParams.chartTitle = '实时水位过程';
		chartParams.seriesData = [
			{type: 'spline',name: '水位',color : 'green',dataVal : 'vals'},
			{type: 'spline',name: '流量',color : '#00E3E3',dataVal : 'values2',yAxis:1}
			];
	}
	chartParams.subChartTitle = bTm + '至' + eTm;
	var sendParams = {bTm:bTm,eTm:eTm,stcd:stcd,dxn:dxn,r:new Date().getTime()};	
	buildChart(tabPanel,startDate,reservoirChartOption,chartParams,sendParams,id,'water');
}

function buildReservoirTable(windowVals,tabPanel){
	var id = tabPanel.attr('id');
	var stcd = tabPanel.data('stcd');
	var dxn = windowVals.dxn;
	var startTime = windowVals.startTime;
	var endTime = windowVals.endTime;

	var sendParams = {bTm:startTime,eTm:endTime,stcd:stcd,dxn:dxn,r:new Date().getTime()};
	var params = $.extend({},windowVals);
	if(id == 'day'){
		params.csvDataHeaders = '序号,日期,水位(m),多年同期水位(m),典型年水位(m),流量(m³/s)';
		params.dataKeys = ['tm','val','value1','value6','value5'];
		params.dataIndex = ['maxWater','minWater','curAvgWater'];
		params.fDataIndex = ['hisMaxWater','hisMinWater','hisAvgWater'];
		params.sotrHistory=['maxWaterSort','minWaterSort','avgWaterSort'];
		params.maxMinAvg=['waterMaxs','waterMins','waterAvgs']
		params.plMaxDateName =['最高水位','最低水位','平均水位'];
		params.warnDayNumKey = 'warDayNum';
		params.cols = [3,5];
		
		params.chartDataTableUrl = '../gis/ReservoirScreen.json?method=getSingleStatDayProcess';
		params.analysisTableUrl = '../gis/ReservoirScreen.json?method=getDayProcessAnalysis';		
	}else if(id == 'hour'){
		params.csvDataHeaders = '序号,日期,水位(m),流量(m³/s)';
		params.dataKeys = ['tm','val','value2'];
		params.chartDataTableUrl = '../gis/ReservoirScreen.json?method=getSingleStatHourProcess';		
	}
	buildTable(tabPanel,params,sendParams,id,'water');
}

function windowReservoirQuery(event){
	var showTabPanel = event.data.panel;
	var windowVals = getWindowVals(showTabPanel,true,false);
	buildReservoirChart(windowVals,showTabPanel);
	buildReservoirTable(windowVals,showTabPanel);
}